/**
 * <p>Helper method to get CSViewerInfoPanel object.</p>
 */
var getCSViewerInfoPanel = function(treePanelObj) {
	var mainWindowObj = treePanelObj.findParentByType('xCSViewerMainWindow', true);
	var infoPanelObj = mainWindowObj.findByType('xCSViewerInfoPanel', true);
	
	return infoPanelObj[0];
}

/**
 * @class CSViewerTreePanel
 * @extends Ext.tree.TreePanel
 * 
 * <p>Tree panel with the following structure:
 * 
 * + Organisation (root)
 *	 + Department
 *		+ Project
 *		  + Employee
 * 
 * </p>
 */
var CSViewerTreePanel = Ext.extend(Ext.tree.TreePanel, {
	xtype      : 'xCSViewerTreePanel',
	id         : 'CSViewerTreePanel',
	title      : 'Structure',
	region     :'west',
	split      : true,
	border     : false,
	height     : 300,
	width      : 400,
	minSize    : 150,
	autoScroll : true,
	animate    : true,
    
    rootVisible : true,
    lines       : false,
    singleExpand: false,
    useArrows   : true,    
 
    loader: new Ext.tree.TreeLoader({
    	dataUrl: 'dispatcher/getList'
	}),
    
    root       : {
        nodeType : 'async',
        text     : 'Mera',
        iconCls  : 'folder',
        id       : '_treeRoot_',
        expanded : true
    },
    
    listeners: {    	
    	contextmenu: function(node, e) {
    		onContextMenu(node, e, this);
    	},
    	
    	click: function(node, eventObj){
    		showInfoPanelContent(node, getCSViewerInfoPanel(this));
	   	},
	   	
	   	load: function(node, eventObj){
	   		var rootNode = this.getRootNode();

	   		if (node == rootNode) {
	   			showInfoPanelContent(rootNode, getCSViewerInfoPanel(this));
	   		}
	   	}
    },
    
    initComponent: function(){	
    	CSViewerTreePanel.superclass.initComponent.call(this);
    }    
});

Ext.reg('xCSViewerTreePanel', CSViewerTreePanel);